昨天設定好新增畫面裡四個Cell的樣式了,今天繼續把四個Cell的功能,和各自連接的畫面用好。
首先要先建立三個分別設定鈴聲,附註,和重複日期的畫面,然後在這個函式裡寫下程式。
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            self.navigationController?.pushViewController(RepeatPageViewController(), animated: true)
        case 1:
            self.navigationController?.pushViewController(LabelPageViewController(), animated: true)
        case 2:
            self.navigationController?.pushViewController(SoundPageViewController(), animated: true)
        default:
            return
        }
    }
設定好Cell的大部分功能和樣式之後,來製作設定鈴聲的畫面。
設定鈴聲的畫面十分簡單,只需要一個TableView就能完成,只是要注意的是你一次只能選擇一個Cell。
    var soundSource = ["口哨", "平靜", "活潑", "音效", "音樂盒", "悅耳", "清脆", "網球"]
    var soundSelect = 0
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        soundSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = soundPageTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SoundPageTableViewCell
        
        cell.SoundLabel.text = soundSource[indexPath.row]
        
        if soundSelect == indexPath.row {
            cell.accessoryType = .checkmark
        }else{
            cell.accessoryType = .none
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        soundSelect = indexPath.row
        
        soundPageTableView.reloadData()
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return soundPageTableView.frame.height / 10
    }
設定鈴聲的畫面大概就像這樣,那麼今天就到這裡,明天換另外兩個畫面。